package config

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

// https://blog.csdn.net/hi_lv_520/article/details/146949865
func LoggerMiddleware() gin.HandlerFunc {

	return func(c *gin.Context) {

		// 打印请求方法和路径
		fmt.Printf("开始处理请求: %s %s\n", c.Request.Method, c.Request.URL.Path)

		// 打印请求参数
		queryParams := c.Request.URL.Query()
		for key, values := range queryParams {

			for _, value := range values {

				fmt.Printf("参数 - %s: %s\n", key, value)
			}
		}

		// 继续处理请求
		c.Next()

		// 请求处理完成后的日志
		fmt.Printf("请求处理完成: %s %s\n", c.Request.Method, c.Request.URL.Path)
	}
}
